<?php

/**
 * telefono actions.
 *
 * @package    sf_sandbox
 * @subpackage telefono
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class telefonoActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
   
   $this->contribuyente_id=$request->getParameter("id");
   $this->telefonos = TelefonoTable::getBuscarTelefonos($this->contribuyente_id);
//     $this->contribuyente = ContribuyenteTable::getBuscarContribuyentexid($this->contribuyente_id);  
       $contribuyente  = Doctrine_Core::getTable('Contribuyente')->find(array($request->getParameter('id')));
  
    $this->setLayout("busqueda"); 
    $this->getResponse()->setTitle('Contribuyente - '.$contribuyente);
  }

  public function executeNew(sfWebRequest $request)
  {
      $this->contribuyente_id=$request->getParameter("id");
      $tel=new Telefono();
      $tel->setContribuyenteId($tel);
       $this->form = new TelefonoForm();
        $this->setLayout("busqueda");
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new TelefonoForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($telefono = Doctrine_Core::getTable('Telefono')->find(array($request->getParameter('id'))), sprintf('Object telefono does not exist (%s).', $request->getParameter('id')));
    $this->form = new TelefonoForm($telefono);
      $this->setLayout("busqueda");
  
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($telefono = Doctrine_Core::getTable('Telefono')->find(array($request->getParameter('id'))), sprintf('Object telefono does not exist (%s).', $request->getParameter('id')));
    $this->form = new TelefonoForm($telefono);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($telefono = Doctrine_Core::getTable('Telefono')->find(array($request->getParameter('id'))), sprintf('Object telefono does not exist (%s).', $request->getParameter('id')));
    $telefono->delete();

    $this->redirect('telefono/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $telefono = $form->save();

      $this->redirect('telefono/index?id='.$telefono->getContribuyenteId());
    }
  }
}
